/*********************************************************************************
 *      Copyright:  (C) 2022 Zhang Changxing<ZhangChangxingVIP@163.com>
 *                  All rights reserved.
 *
 *       Filename:  mosq.h
 *    Description:  This file is used to connect to the MQTT server, publish and subscribe topics.
 *                 
 *        Version:  1.0.0(05/1/2022)
 *         Author:  Zhang Changxing <ZhangChangxingVIP@163.com>
 *      ChangeLog:  1, Release initial version on "05/1/2022  01:33:25 AM"
 *                 
 ********************************************************************************/
#ifndef  _MY_MOSQUITTO_H_
#define  _MY_MOSQUITTO_H_

#include "main.h"

/****************************************************************************************************
 *   description:   Connect to brokers using the MQTT protocol
 *          args:   $mqtt_connect_ctx:    The configuration information structure pointer that connects the broker
 *  return value:      <0: failure,    =0:ok 
 ****************************************************************************************************/
int mqtt_init(iotd_ctx_t *iotd_ctx);

/****************************************************************************************************
 *   description:   Sends data to connected servers
 *          args:   $pub_ctx:    The configuration information structure that connects the broker
 *  return value:      <0: failure,    =0:ok 
 ****************************************************************************************************/
int publish_data(pub_ctx_t *pub_ctx);

/****************************************************************************************************
 *   description:   Subscribe to topic messages
 *          args:   $sub_ctx:    The configuration information structure that connects the broker
 *  return value:      <0: failure,    =0:ok 
 ****************************************************************************************************/
int subscribe_data(sub_ctx_t sub_ctx);

/****************************************************************************************************
 *   description:   Unsubscribe topic messages
 *          args:   $sub_ctx:    The configuration information structure that connects the broker
 *  return value:      <0: failure,    =0:ok 
 ****************************************************************************************************/
int unsubscribe_data(sub_ctx_t sub_ctx);

/****************************************************************************************************
 *   description:   Sends data to connected servers
 *  return value:      <0: failure,    =0:ok 
 ****************************************************************************************************/
int mosquitto_cleanup(void);


int mqtt_connect(mqtt_connect_ctx_t *mqtt_connect_ctx);

int mqtt_reconnect(void);

/****************************************************************************************************
 *   description:   Creating a child thread executes this function, which is used to process messages\
                    and commands from the server
 *          args:   $args:    The configuration information structure that connects the broker
 ****************************************************************************************************/
void *thread_worker(void *args);


int mosq_loop_start(iotd_ctx_t *iotd_ctx);


#endif